package im.vinci.server.discovery.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import im.vinci.server.discovery.domain.Category;
import im.vinci.server.discovery.domain.Channel;
import im.vinci.server.discovery.domain.Music;
import im.vinci.server.discovery.domain.MusicList;
import im.vinci.server.utils.JsonUtils;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by mingjie on 16/10/28.
 */
public class MusicDataFile {
    // 音乐id 到 音乐
    private HashMap<Long, Music> musicMap;

    // 歌单id 到音乐id列表
    private HashMap<Long, List<Long>> musicListMap;

    private List<Channel> channels;

    private List<Category> categories;

    public HashMap<Long, Music> getMusicMap() {
        return musicMap;
    }

    public void setMusicMap(HashMap<Long, Music> musicMap) {
        this.musicMap = musicMap;
    }

    public HashMap<Long, List<Long>> getMusicListMap() {
        return musicListMap;
    }

    public void setMusicListMap(HashMap<Long, List<Long>> musicListMap) {
        this.musicListMap = musicListMap;
    }

    public List<Channel> getChannels() {
        return channels;
    }

    public void setChannels(List<Channel> channels) {
        this.channels = channels;
    }

    public List<Category> getCategories() {
        return categories;
    }

    public void setCategories(List<Category> categories) {
        this.categories = categories;
    }


    public static void main(String[] args)
    {
        // music
        Music music1 = new Music();
        music1.setLyricFile("http://img.xiami.net/lyric/32/122832_1420699243977_8815.lrc");
        music1.setSoundEqualizer(0);
        music1.setSoundEffect(0);
        music1.setArtistId(1805);
        music1.setTagCounts("[1,1,1,1,1,1,1,1,1,1,1,1,1]");
        music1.setPlaySeconds(282);
        music1.setSingers("李娜");
        music1.setAlbumName("信天游");
        music1.setTags("[\\\"歌词\\\",\\\"好听\\\",\\\"歧义\\\",\\\"民歌\\\",\\\"喜欢\\\",\\\"信天游\\\",\\\"永远的经典\\\",\\\"信天游 歌词\\\",\\\"未分类\\\",\\\"往昔\\\",\\\"西北\\\",\\\"李娜\\\",\\\"经典\\\"]");
        music1.setSongName("信天游");
        music1.setListenFile("http://m5.file.xiami.com/805/1805/9951/122832_111486_l.mp3?auth_key=4089d84ec6954da075cf4c9cb038c27a-1477440000-0-null");
        music1.setSongId(122832);
        music1.setAlbumLogo("http://img.xiami.net/images/pic/04/04/10114813207m_1.jpg");
        music1.setArtistLogo("http://img.xiami.net/images/artistlogo/15/14213911403115_1.jpg");
        music1.setSongType("xiami");
        music1.setArtist("李娜");
        music1.setAlbumId(9951);
        music1.setPlayCounts(2048);

        Music music2 = new Music();
        music2.setLyricFile("http://img.xiami.net/lyric/32/122832_1420699243977_8815.lrc");
        music2.setSoundEqualizer(0);
        music2.setSoundEffect(0);
        music2.setArtistId(1805);
        music2.setTagCounts("[1,1,1,1,1,1,1,1,1,1,1,1,1]");
        music2.setPlaySeconds(282);
        music2.setSingers("李娜");
        music2.setAlbumName("信天游");
        music2.setTags("[\\\"歌词\\\",\\\"好听\\\",\\\"歧义\\\",\\\"民歌\\\",\\\"喜欢\\\",\\\"信天游\\\",\\\"永远的经典\\\",\\\"信天游 歌词\\\",\\\"未分类\\\",\\\"往昔\\\",\\\"西北\\\",\\\"李娜\\\",\\\"经典\\\"]");
        music2.setSongName("信天游");
        music2.setListenFile("http://m5.file.xiami.com/805/1805/9951/122832_111486_l.mp3?auth_key=4089d84ec6954da075cf4c9cb038c27a-1477440000-0-null");
        music2.setSongId(122833);
        music2.setAlbumLogo("http://img.xiami.net/images/pic/04/04/10114813207m_1.jpg");
        music2.setArtistLogo("http://img.xiami.net/images/artistlogo/15/14213911403115_1.jpg");
        music2.setSongType("xiami");
        music2.setArtist("李娜");
        music2.setAlbumId(9951);
        music2.setPlayCounts(2048);

        //
        List<Music> musicList = new ArrayList<Music>();
        musicList.add(music1);

        List<Music> list = new ArrayList<Music>();
        list.add(music1);
        list.add(music2);

        // music list
        MusicList musicList1 = new MusicList();
        musicList1.setListId(1);
        musicList1.setDesc("跑步");
        musicList1.setCreatorId(0);
        musicList1.setCreator("system");
        musicList1.setCreateTime(System.currentTimeMillis());
        musicList1.setLogo("http://img.xiami.net/images/pic/04/04/10114813207m_1.jpg");
        musicList1.setName("跑步");

        MusicList musicList2 = new MusicList();
        musicList2.setListId(2);
        musicList2.setDesc("晴天");
        musicList2.setCreatorId(0);
        musicList2.setCreator("system");
        musicList2.setCreateTime(System.currentTimeMillis());
        musicList2.setLogo("http://img.xiami.net/images/pic/04/04/10114813207m_1.jpg");
        musicList2.setName("晴天");

        List<MusicList> mlList = new ArrayList<MusicList>();
        mlList.add(musicList1);
        mlList.add(musicList2);

        // channels
        Channel channel1 = new Channel();
        channel1.setChannelId(1);
        channel1.setChannelName("3D电台");
        channel1.setChannelImg("http://img.xiami.net/images/pic/04/04/10114813207m_1.jpg");
        channel1.setData(mlList);
        channel1.setPos(1);

        Channel channel2 = new Channel();
        channel2.setChannelId(2);
        channel2.setChannelName("天气电台");
        channel2.setChannelImg("http://img.xiami.net/images/pic/04/04/10114813207m_1.jpg");
        channel2.setData(mlList);
        channel2.setPos(2);

        List<Channel> channelList = new ArrayList<Channel>();
        channelList.add(channel1);
        channelList.add(channel2);

        // categories
        // 推荐
        Category<Category> recommend = new Category<Category>();
        recommend.setCategoryId(1);
        recommend.setCategoryName("推荐");
        recommend.setCategoryType("category");
        recommend.setPos(1);

        Category<Music> jx = new Category<Music>();
        jx.setCategoryName("精选歌单");
        jx.setCategoryType("music");
        jx.setCategoryId(12);
        jx.setPos(1);
        jx.setData(musicList);

        Category<MusicList> ck = new Category<MusicList>();
        ck.setCategoryId(13);
        ck.setCategoryType("musiclist");
        ck.setCategoryName("此刻电台");
        ck.setPos(2);
        ck.setData(mlList);

        List<Category> categoryList = new ArrayList<Category>();
        categoryList.add(jx);
        categoryList.add(ck);
        recommend.setData(categoryList);

        // 热门
        Category<Music> day = new Category<Music>();
        day.setCategoryId(24);
        day.setCategoryType("music");
        day.setCategoryName("本日最热");
        day.setPos(1);
        day.setData(list);

        Category<Music> week = new Category<Music>();
        week.setCategoryId(26);
        week.setCategoryType("music");
        week.setCategoryName("本周最热");
        week.setPos(2);
        week.setData(list);

        List<Category> categories1 = new ArrayList<Category>();
        categories1.add(day);
        categories1.add(week);

        Category<Category> hot = new Category<Category>();
        hot.setCategoryName("热门");
        hot.setCategoryType("category");
        hot.setCategoryId(2);
        hot.setPos(2);
        hot.setData(categories1);

        // 最新
        Category<Music> news = new Category<Music>();
        news.setCategoryName("最新");
        news.setCategoryType("music");
        news.setCategoryId(3);
        news.setPos(3);
        news.setData(list);

        //
        List<Category> categories = new ArrayList<Category>();
        categories.add(recommend);
        categories.add(hot);
        categories.add(news);

        HashMap<Long, List<Long>> musicListMap = new HashMap<Long, List<Long>>();
        List<Long> musicIdList = new ArrayList<Long>();
        musicIdList.add(122832L);
        musicIdList.add(122833L);
        musicListMap.put(1L, musicIdList);

        HashMap<Long, Music> musicMap = new HashMap<Long, Music>();
        musicMap.put(music1.getSongId(), music1);
        musicMap.put(music2.getSongId(), music2);

        MusicDataFile dataFile = new MusicDataFile();
        dataFile.setCategories(categories);
        dataFile.setChannels(channelList);
        dataFile.setMusicMap(musicMap);
        dataFile.setMusicListMap(musicListMap);

        try {
            JsonUtils.getHttpObjectMapperInstance().writeValue(new FileWriter("DiscoveryData.json"),dataFile);
        } catch (JsonProcessingException e) {
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
